package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.AdminDAO;


public class DeleteAdminServlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html; charset=UTF-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		
		
		int id=Integer.parseInt(request.getParameter("id"));
		
		AdminDAO Admindao=new AdminDAO();
		int i = Admindao.deleteAdminById(id);
		
		if(i>0)
		{
			out.print("<script>alert('删除成功！');location.href='admin/admin_list.jsp';</script>");
		}
		else
		{
			out.print("<script>alert('删除失败！');history.go(-1);</script>");
		}
	}

}
;